package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    /**
     * 根据查询条件查询员工
     */
    List<Emp> list(EmpQueryParam empQueryParam);

    /**
     * 新增员工数据
     * useGeneratedKeys:开启主键回填,是否主键自增
     * keyProperty:指定主键回填到哪个属性中,指定实体类的属性名
     * keyColumn:指定数据库主键的列名
     */
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @Insert("insert into emp(username,password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    // 根据id查询员工信息
    @Select("select *from emp where id= #{id}")
    Emp getById(Integer id);

    // 修改员工信息
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @Update("update emp set username=#{username},password=#{password},name=#{name},gender=#{gender},phone=#{phone},job=#{job},salary=#{salary}" +
            ",image=#{image},entry_date=#{entryDate},dept_id=#{deptId},create_time=#{createTime},update_time=#{updateTime} where id=#{id}")
    void update(Emp emp);

    @Select("select * from emp")
    public List<Emp> searchAll();

    /**
     * 批量删除员工信息
     */
    void deleteByIds(List<Integer> ids);


// 统计员工岗位数据
    @MapKey("pos")// 指定返回的map的key
    List<Map<String, Object>> countEmpJobData();

    // 统计员工性别数据
    @MapKey("name")// 指定返回的map的key
    List<Map> countEmpGenderData();


    /**
     * 根据用户名和密码查询员工信息
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsernameAndPassword(Emp emp);

}